#!/usr/bin/env python
# encoding: utf-8

print "cwconvert"

# built-in stuff
import unittest
import sys
sys.path.append("../")
# home made stuff
from scriptgoodies import getTestingEnvironment
# stuff to test
from cwconvert import *

class CwConvertTest(unittest.TestCase):
	
	def setUp(self):
		self.env = getTestingEnvironment("cwconvert.json","fr_cwconvert.json")
		self.env["constants"]["language"] = "fr"
	
	def isIncluded(self,s,expectedResult):
		self.env["context"]["selection"] = (s[:s.rindex(" ")+1] if " " in s else s)
		self.env["meta"]["richSuffix"] = s[s.index("cwConvertir")+len("cwConvertir"):]
		result = dict(main(self.env))
		for (directive,data) in expectedResult.iteritems():
			self.assertIn(directive,result)
			if type(data) is dict:
				for (k,v) in data.iteritems():
					self.assertIn(k,result[directive])
					self.assertEqual(v,result[directive][k])
			else:
				self.assertEqual(data,result[directive])
	
	def testImplicit(self):
		self.isIncluded(u"1 cwConvertir",{"messageBox":u"longueur: 1 m = 0.001 km."})
	
	def testExplicitTarget(self):
		self.isIncluded(u"1 cwConvertirmm",{"messageBox":u"longueur: 1 m = 1000.0 mm."})
	
	def testExplicitBase(self):
		self.isIncluded(u"1 hm cwConvertir",{"messageBox":u"longueur: 1 hm = 0.1 km."})
	
	def testRateTable(self):
		self.isIncluded(u"cwConvertir",{"messageBox":u"longueur: conversions for 1 km."})
	
	def testImplicitWithGivenCategory(self):
		self.isIncluded(u"1 cwConvertirPoids",{"messageBox":u"poids: 1 kg = 1000.0 g."})
	
	def testExplicitTargetWithGivenCategory(self):
		self.isIncluded(u"1 mg cwConvertirPoidsµg",{"messageBox":u"poids: 1 mg = 1000.0 µg."})
	
	def testExplicitBaseWithGivenCategory(self):
		self.isIncluded(u"1 mg cwConvertirPoids",{"messageBox":u"poids: 1 mg = 0.001 g."})
	
	def testRateTableWithGivenCategory(self):
		self.isIncluded(u"cwConvertirPoids",{"messageBox":u"poids: conversions for 1 g."})
	
	
	

if __name__ == '__main__':
	unittest.main()


